<?php

namespace app\common\model;

use addons\shopro\model\User;
use think\Model;

/**
 * 会员余额日志模型
 */
class MoneyLog Extends Model
{

    // 表名
    protected $name = 'user_money_log';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = '';
    // 追加属性
    protected $append = [
        'createtime_text'
    ];

    // 余额变更记录
    public static function getList()
    {
        $user = User::info();

        $lists = self::where(['user_id' => $user->id])->order('id desc')->paginate(10);

        return $lists;
    }

    public function getCreatetimeTextAttr($val,$data)
    {
        $val = !empty($data['createtime']) ? date('Y-m-d H:i:s',$data['createtime']) : '';
        return $val;
    }
}
